import { createRouter, createWebHashHistory } from 'vue-router';
export default createRouter({
  // 回到顶部
  scrollBehavior() {
    return { top: 0 };
  },
  history: createWebHashHistory(),
  routes: [
    {
      // 首页
      path: '/',
      // 懒加载 页面初始化的时候更节省性能
      name: '首页',
      component: () => import('@/views/home/index.vue'),
      // 重定向
      redirect: '/home',
      children: [
        // 首页
        {
          path: '/home',
          name: 'home',
          component: () => import('@/views/home/home-page/index.vue'),
        },
        {
          // 分类
          path: '/category/:id',
          name: 'category',
          component: () => import('@/views/category/index.vue'),
        },
        {
          path: '/category/sub/:id',
          name: 'sub',
          component: () => import('@/views/category/sub/index.vue'),
        },
        {
          path: '/product/:id',
          name: 'product',
          component: () => import('@/views/product/index.vue'),
        },
        {
          path: '/cart',
          name: 'cart',
          component: () => import('@/views/cart/index.vue'),
        },
      ],
    },
    {
      // 登录页
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/index.vue'),
    },
  ],

});

